from datetime import datetime

class StandardModel:
    def __init__(self,
                 book_number: str = None,
                 quota_number: str = None,
                 quota_name: str = None,
                 work_content: str = None,
                 unit: str = None,
                 basic_quota: str = None,
                 base_price: str = None,
                 unit_weight: str = None,
                 labor_cost: str = None,
                 material_cost: str = None,
                 machine_cost: str = None,
                 main_material: str = None,
                 data_id: int = None,
                 created_at: datetime = None,
                 updated_at: datetime = None):
        self.id = data_id
        self.book_number = book_number
        self.quota_number = quota_number
        self.quota_name = quota_name
        self.work_content = work_content
        self.unit = unit
        self.basic_quota = basic_quota
        self.base_price = base_price if base_price and base_price != '' and base_price != ' ' else 0
        self.unit_weight = unit_weight if unit_weight and unit_weight != '' and unit_weight != ' ' else 0
        self.labor_cost = labor_cost if labor_cost and labor_cost != '' and labor_cost != ' ' else 0
        self.material_cost = material_cost if material_cost and material_cost != '' and material_cost != ' ' else 0
        self.machine_cost = machine_cost if machine_cost and machine_cost != '' and machine_cost != ' ' else 0
        self.main_material = main_material
        self.created_at = created_at or datetime.now()
        self.updated_at = updated_at or datetime.now()

    def to_dict(self) -> dict:
        return {
            'id': self.id,
            'book_number': self.book_number,
            'quota_number': self.quota_number,
            'quota_name': self.quota_name,
            'work_content': self.work_content,
            'unit': self.unit,
            'basic_quota': self.basic_quota,
            'base_price': self.base_price,
            'unit_weight': self.unit_weight,
            'labor_cost': self.labor_cost,
            'material_cost': self.material_cost,
            'machine_cost': self.machine_cost,
            'main_material': self.main_material,
            'created_at': self.created_at.strftime('%Y-%m-%d %H:%M:%S') if self.created_at else None,
            'updated_at': self.updated_at.strftime('%Y-%m-%d %H:%M:%S') if self.updated_at else None
        }