# frozen_string_literal: true

module Sessions
  class CreateAction < ApplicationAction
    def perform(input)
      if input.valid?
        @current_user = UserRepository.new.find_for_authentication(input)
        unless @current_user
          failure(
            Upgrow::Error.new(
              message: 'Invalid email or password.',
              code: :invalid_email_or_password,
              attribute: :password
            ),
            Upgrow::Error.new(attribute: :email)
          )
        end
      else
        failure(input.errors)
      end
    end
  end
end