import random
import requests
import logging

from odoo import models, fields, api
from odoo.exceptions import ValidationError

_logger = logging.getLogger(__name__)

class ResCompany(models.Model):
    _inherit = 'res.company'

    # -- SMS API Settings --
    sms_mode = fields.Selection(
        [('test', 'Test Mode (Disable SMS Sending)'), ('prod', 'Production')],
        string="SMS Mode",
        default='test',
        required=True,
        help="In Test Mode, OTP will be generated and logged but no SMS will be sent."
    )
    sms_api_url = fields.Char(string="SMS API URL")
    sms_api_token = fields.Char(string="SMS API Token", help="Your Bearer token for the SMS API.")
    sms_sender_name = fields.Char(string="SMS Sender Name")


class ResConfigSettings(models.TransientModel):
    _inherit = 'res.config.settings'

    # -- SMS API Settings --
    # The 'related' attribute links these transient fields to the fields on res.company
    sms_mode = fields.Selection(
        related='company_id.sms_mode',
        readonly=False,
        required=True
    )
    sms_api_url = fields.Char(
        related='company_id.sms_api_url',
        readonly=False
    )
    sms_api_token = fields.Char(
        related='company_id.sms_api_token',
        readonly=False
    )
    sms_sender_name = fields.Char(
        related='company_id.sms_sender_name',
        readonly=False
    )