from odoo import fields, models


class EncoachAILog(models.Model):
    _name = "encoach.ai.log"
    _description = "AI Service Call Log"
    _order = "create_date desc"

    service = fields.Selection(
        [
            ("openai", "OpenAI"),
            ("whisper", "Whisper"),
            ("polly", "AWS Polly"),
            ("elevenlabs", "ElevenLabs"),
            ("gptzero", "GPTZero"),
            ("elai", "ELAI"),
            ("coach", "AI Coach"),
        ],
        required=True,
        index=True,
    )
    action = fields.Char(index=True)
    model_used = fields.Char()
    prompt_tokens = fields.Integer(default=0)
    completion_tokens = fields.Integer(default=0)
    total_tokens = fields.Integer(default=0)
    latency_ms = fields.Integer()
    status = fields.Selection(
        [("success", "Success"), ("error", "Error"), ("timeout", "Timeout")],
        default="success",
    )
    error_message = fields.Text()
    user_id = fields.Many2one("res.users", default=lambda self: self.env.uid)
    input_preview = fields.Text()
    output_preview = fields.Text()
