module Youtube
  # Credenziali del canale YouTube Match Live TV (Premium Light), da ENV.
  class PlatformCredential
    attr_accessor :access_token, :expires_at

    def refresh_token
      ENV["YOUTUBE_PLATFORM_REFRESH_TOKEN"].presence
    end

    def expired?
      expires_at.present? && expires_at < Time.current
    end

    def update!(attrs)
      self.access_token = attrs[:access_token] if attrs.key?(:access_token)
      self.expires_at = attrs[:expires_at] if attrs.key?(:expires_at)
    end

    def self.configured?
      ENV["YOUTUBE_PLATFORM_REFRESH_TOKEN"].present?
    end
  end
end
