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


class ParmSchema(Schema):
    UserID = fields.Str()
    Version = fields.Str()
    Env = fields.Str()
    Session = fields.Integer()
    Source = fields.Str()
    RC = fields.Integer()
    ResultMsg = fields.Str()

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


class UserVendorSchema(Schema):
    VendorId = fields.Str()
    VendorCompany = fields.Str()
    VendorAddress = fields.Str()
    VendorCity = fields.Str()
    VendorState = fields.Str()
    VendorZip = fields.Str()
    VendorContact = fields.Str()
    VendorPhone = fields.Str()

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


class UserVendorsSchema(Schema):
    Parms = fields.Nested(ParmSchema)
    DataList = fields.Nested(UserVendorSchema, many=True)

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

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


class ParmSchema(Schema):
    UserID = fields.Str()
    Version = fields.Str()
    Env = fields.Str()
    Session = fields.Integer()
    Source = fields.Str()
    RC = fields.Integer()
    ResultMsg = fields.Str()

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


class UserVendorSchema(Schema):
    VendorId = fields.Str()
    VendorCompany = fields.Str()
    VendorAddress = fields.Str()
    VendorCity = fields.Str()
    VendorState = fields.Str()
    VendorZip = fields.Str()
    VendorContact = fields.Str()
    VendorPhone = fields.Str()

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


class UserVendorsSchema(Schema):
    Parms = fields.Nested(ParmSchema)
    DataList = fields.Nested(UserVendorSchema, many=True)

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