from marshmallow import fields, post_load
from portals.wwits.apis.rest import BaseSchemaExcludeFields as Schema
from .models import ParmModel, UpdateCannedSpecialInstructionsModel


class ParmSchema(Schema):
    UserID = fields.Str()
    Version = fields.Str()
    Env = fields.Str()
    Source = fields.Str()
    Session = fields.Int()
    Entity = fields.Str()
    EntityRecid = fields.Int()
    EntityCount = fields.Int()
    Mode = fields.Str()
    CustCode = fields.Str()
    Criteria = fields.Str(allow_none=True)
    Value = fields.Str(allow_none=True)
    Excluded = fields.Bool()
    NoRmkSets = fields.Int()
    NoDocSets = fields.Int()
    Remark1 = fields.Str(allow_none=True)
    Remark2 = fields.Str(allow_none=True)
    Remark3 = fields.Str(allow_none=True)
    Remark4 = fields.Str(allow_none=True)
    Remark5 = fields.Str(allow_none=True)
    Remark6 = fields.Str(allow_none=True)
    Remark7 = fields.Str(data_key="ReMark7", allow_none=True)
    Remark8 = fields.Str(allow_none=True)
    Remark9 = fields.Str(allow_none=True)
    Remark10 = fields.Str(allow_none=True)
    DocType1 = fields.Str(allow_none=True)
    DocValue1 = fields.Str(allow_none=True)
    DocType2 = fields.Str(allow_none=True)
    DocValue2 = fields.Str(allow_none=True)
    DocType3 = fields.Str(allow_none=True)
    DocValue3 = fields.Str(allow_none=True)
    RC = fields.Int()
    ResultMsg = fields.Str()

    @post_load
    def make_schema(self, data, **kwargs):
        return ParmModel(**data)


class UpdateCannedSpecialInstructionsSchema(Schema):
    Parms = fields.Nested(ParmSchema)

    @post_load
    def make_schema(self, data, **kwargs):
        return UpdateCannedSpecialInstructionsModel(**data)
