class GekanatorAiRun < ApplicationRecord
  STATUSES = ['pending', 'running', 'succeeded', 'failed', 'blocked_budget'].freeze

  belongs_to :gekanator_question_suggestion

  validates :model, presence: true, length: { maximum: 255 }
  validates :status, presence: true, inclusion: { in: STATUSES }
  validates :input_tokens,
            presence: true,
            numericality: { only_integer: true, greater_than_or_equal_to: 0 }
  validates :output_tokens,
            presence: true,
            numericality: { only_integer: true, greater_than_or_equal_to: 0 }
  validates :estimated_cost_jpy,
            presence: true,
            numericality: { greater_than_or_equal_to: 0 }

  scope :this_month, lambda {
    where(created_at: Time.current.beginning_of_month..Time.current.end_of_month)
  }
end
