from odoo import models, fields

class SosTestingParameters(models.Model):
    _name = 'sos_testing_parameters'
    _description = 'SOS Testing Parameters'
    _rec_name='fg_name'

    fg_name = fields.Many2one('sos_fg',string="FG Name")
    parameter_ids = fields.One2many('sos_parameter', 'testing_id', string= 'In-Process/BRR Testing Parameters',copy=True)
    fir_parameter_ids = fields.One2many('sos_parameter_fir', 'testing_id', string= 'FIR Testing Parameters',copy=True)
    specification_ids = fields.One2many('sos_specification', 'spec_id', string='Specifications',copy=True)
    deliverables_ids = fields.One2many('sos_deliverables', 'accessory_id', string='Deliverables',copy=True)
    defective_ids = fields.One2many('sos_defectives', 'defective_id', string='Defectives',copy=True)

class SosParameter(models.Model):
    _name = 'sos_parameter'
    _description = 'SOS Parameter'
    sequence = fields.Integer(string="sequence")
    name = fields.Char(string='Parameter Name', required=True)
    inspection_decision = fields.Selection([('PASS','PASS'),('FAIL','FAIL')],string="Inspection Decision")
    specification = fields.Char(string="Specification")
    results = fields.Text(string="Results")
    testing_id = fields.Many2one('sos_testing_parameters', string='Testing Parameters', ondelete='cascade')

class SosParameter_fir(models.Model):
    _name = 'sos_parameter_fir'
    _description = 'SOS FIR Testing Parameter'
    sequence = fields.Integer(string="sequence")
    name = fields.Char(string='Parameter Name', required=True)
    inspection_decision = fields.Selection([('PASS','PASS'),('FAIL','FAIL')],string="Inspection Decision")
    specification = fields.Char(string="Specification")
    results = fields.Text(string="Results")
    testing_id = fields.Many2one('sos_testing_parameters', string='Testing Parameters', ondelete='cascade')


class Sos_Specifications(models.Model):
    _name = 'sos_specification'
    _description = 'SOS Specification'

    name = fields.Char(string='Specification Name', required=True)
    spec_id = fields.Many2one('sos_testing_parameters', string='Testing Parameters', ondelete='cascade')

class Sos_Deliverables(models.Model):
    _name = 'sos_deliverables'
    _description = 'SOS FG Deliverables'

    name = fields.Char(string='Accessories Name', required=True)
    accessory_id = fields.Many2one('sos_testing_parameters', string='Deliverables', ondelete='cascade')

class Sos_Defectives(models.Model):
    _name = 'sos_defectives'
    _description = 'SOS FG Defectives'

    name = fields.Char(string='Defective Name', required=True)
    defective_id = fields.Many2one('sos_testing_parameters', string='Defectives', ondelete='cascade')

# SFG Configurations

class SOS_SFG_Config(models.Model):
    _name = 'sos_sfg_configuration'
    _description = 'SOS SFG Configuration'
    _rec_name = 'sfg_name'

    sfg_name = fields.Char(string="SFG Category")
    parameter_ids = fields.One2many('sos_sfg_configuration_line', 'testing_id', string= 'Testing Parameters',copy=True)
    defective_ids = fields.One2many('sos_sfg_defective_line', 'ref_id', string= 'Defectives',copy=True)


class SOS_SFG_Config_Line(models.Model):
    _name = 'sos_sfg_configuration_line'
    _description = 'SOS SFG Testing Parameter'

    sequence = fields.Integer(string="sequence")
    name = fields.Char(string='Parameter Name', required=True)
    observation = fields.Char(string='Required Observation', required=True)
    obtained_observation = fields.Char(string='Obtained Observation')
    testing_id = fields.Many2one('sos_sfg_configuration', string='Testing Parameters', ondelete='cascade')

class SOS_SFG_Defective_Line(models.Model):
    _name = 'sos_sfg_defective_line'
    _description = 'SOS SFG Defectives'

    ref_id = fields.Many2one('sos_sfg_configuration', string='SFG Category', ondelete='cascade')
    sequence = fields.Integer(string="sequence")
    name = fields.Char(string='Defective Name', required=True)
# Material Configurations

class SOS_Material_Config(models.Model):
    _name = 'sos_material_configuration'
    _description = 'SOS Material Configuration'
    _rec_name = 'material_name'

    material_name = fields.Char(string="Material Category")
    parameter_ids = fields.One2many('sos_material_configuration_line', 'testing_id', string= 'Testing Parameters',copy=True)
    defective_ids = fields.One2many('sos_material_defective_line', 'ref_id', string= 'Defectives',copy=True)

class SOS_Material_Config_Line(models.Model):
    _name = 'sos_material_configuration_line'
    _description = 'SOS Material Testing Parameter'

    sequence = fields.Integer(string="sequence")
    name = fields.Char(string='Parameter Name', required=True)
    observation = fields.Char(string='Required Observation', required=True)
    obtained_observation = fields.Char(string='Obtained Observation')
    testing_id = fields.Many2one('sos_material_configuration', string='Testing Parameters', ondelete='cascade')

class SOS_Material_Defective_Line(models.Model):
    _name = 'sos_material_defective_line'
    _description = 'SOS Material Defectives'

    sequence = fields.Integer(string="sequence")
    name = fields.Char(string='Defective Name', required=True)
    ref_id = fields.Many2one('sos_material_configuration', string='Defectives', ondelete='cascade')
