const mongoose = require("mongoose");
const Schema = mongoose.Schema
const { constantValues, mongooseConstantValues } = require("../apps/common/systemConstents")

const purchaseOrderSchema = mongoose.Schema({
    orderNumber: { type: String },
    orderAmt: { type: Object },
    shippingAmt: { type: Number },
    taxLines: [],
    source: { type: String },
    merchantId: { type: String },
    marketPlace: { type: String },    
    customerId: { type: String },
    shopifyOrderId: { type: String },
    fulfillmentStatus: { type: Number, default: constantValues.FULLFILLMENT_STATUS },
    sku: { type: String },
    productInfo: {},
    varient: [],
    sid: { type: String },
    productTitle: { type: String },
    invoicedesc: { type: String },
    storeDomain: { type: String },
    orderCreatedAt: { type: Date },
    orderUpdatedAt: { type: Date },
    qty: { type: Number },
    igst: { type: Number },
    hsn: { type: String },
    date:{type:String},
    customer: {},
    history: { type: Array },
    netAmount: { type: Number },
    createdAt: { type: Date, default: new Date().toISOString() },
    updatedAt: { type: Date, default: new Date().toISOString() },
    statusChangeHistory: { type: Array },
    awbNumber: { type: String },
    lastMileStatus: { type: String },
    paymentStatus: { type: Number, default: constantValues.PAYMENT_STATUS },
    orderId: {type: Schema.Types.ObjectId},
    productId: {type: Schema.Types.ObjectId},
    imgUrl: {type: Object, default: {}},
    discountCodes: {type: Array},
    paymentDetails: {type: Object},
    // platform:{
    //     type: String,
    //   },
    taxLines: {type: Array},
    billingAddress: {type: Object},
    shippingAddress: {type: Object},
    note: {type: String},
    paymentMethod: {type: Array},
    pStatus: {type: String},
    invoicePdf: {type: Array},
    orderStatus : {type: String},
    opStatus : {type: String},
    orReason : {type: String},
    oshipStatus : {type: String},
    orStatus : {type: String},
    odStatus : {type: String},
    ocStatus : {type: String},
    omStatus : {type: String},
    orFee : {type: String},
    rtFee : {type: String},
    deliverDate : {type: Date},
    cancelTime : {type: Date},
    refundTime : {type: Date},
    trackingNo : {type: String},
    shipApplyStatus : {type: String},
    shipApplyModiDate : {type: Date},
    carrierName : {type: String},
    carrierId : {type: String},
    shipComment : {type: String},
    shipMethod : {type: String},
    systemComment : {type: String},
    resellerPrice:{type:Number},
    rfm: {type: Boolean, default: false },
    scanHistory: {type: Array},
    scanCount: {type: Number, default: 0},
    deliveredOn: {type: Date},
    orderDate: {type: Date},
    dispatchDate: {type: Date},
    supplierPrice: {type: Number},
    cffTrackingNo : {type: String},
    op_code : {type: String},
    cffrefOrder : {type: String}, 
    iu: Number,
    rto: {
        type: Number
    }, 
    invoiceFlag: {type: Number}, 
    scanStatus : {type : Number} ,
    isDelete : {type: Boolean, default: false} ,
    orderPlaceDate:{ type: String},

},  {
    timestamps: true,
  })

module.exports = mongoose.model('PurchaseOrder', purchaseOrderSchema)

// orders_status   = orderStatus
// orders_status_payment =  opStatus
// order_refund_reason = orReason
// orders_status_shipping  = oshipStatus
// orders_status_return  = orStatus
// orders_status_dispute  = odStatus
// orders_status_comment = ocStatus
// orders_status_mail = omStatus
// order_refund_fee   = orFee
// refund_transaction_fee  = rtFee
// cancel_time = cancelTime
// refund_time = refundTime
// os_tracking_no  = trackingNo
// os_date_deliver  = deliverDate 
// os_apply_status  = shipApplyStatus
// os_apply_modi_date   = shipApplyModiDate
// carrier_name   = carrierName
// carrier_id   = carrierId
// os_comment  = shipComment
// shipping_method  = shipMethod
// system_comment = systemComment
