extend type Query {
    coupons(
        text: String @where(operator: "like", key: "code")
        language: String @eq
        orderBy: _
            @orderBy(
                columns: [
                    "created_at"
                    "updated_at"
                    "code"
                    "amount"
                    "minimum_cart_amount"
                    "expire_at"
                    "active_from"
                ]
            )
    ): [Coupon!]! @paginate(defaultCount: 15)
    coupon(id: ID @eq, code: String @eq, language: String @eq): Coupon @find
}

type Coupon {
    id: ID!
    code: String!
    description: String
    orders: [Order] @hasMany
    type: String!
    language: String
    translated_languages: [String]
    image: Attachment
    is_valid: Boolean
    message: String
    amount: Float!
    minimum_cart_amount: Float!
    sub_total: Float
    active_from: String!
    expire_at: String!
    created_at: DateTime
    updated_at: DateTime
}

input CreateCouponInput {
    code: String!
        @rules(
            apply: ["max:20"]
            messages: {
                max: "Code should be min 20 character"
            }
        )
    type: String!
    language: String
    amount: Float!
    minimum_cart_amount: Float!
    description: String
        @rules(
            apply: ["max:1000"]
            messages: { max: "Description should be max 1000 character" }
        )
    image: AttachmentInput
    active_from: String!
    expire_at: String!
}

input UpdateCouponInput {
    id: ID!
    code: String
        @rules(
            apply: ["max:20"]
            messages: {
                max: "Code should be min 20 character"
            }
        )
    type: String!
    amount: Float!
    minimum_cart_amount: Float!
    language: String
    description: String
        @rules(
            apply: ["max:1000"]
            messages: { max: "Description should be max 1000 character" }
        )
    image: AttachmentInput
    active_from: String!
    expire_at: String!
}

type VerifyCouponResponse {
    is_valid: Boolean!
    message:String
    coupon: Coupon
}

extend type Mutation {
    createCoupon(input: CreateCouponInput! @spread): Coupon
        @field(resolver: "CouponMutator@store")
    updateCoupon(input: UpdateCouponInput! @spread): Coupon
        @field(resolver: "CouponMutator@update")
    deleteCoupon(id: ID!): Coupon @delete @can(ability: "super_admin")
    verifyCoupon(code: String! , sub_total:Float!): VerifyCouponResponse
        @field(resolver: "CouponMutator@verify")
    restoreCoupon(id: ID!): Coupon @restore @can(ability: "super_admin")
}
