// Code generated by sqlc. DO NOT EDIT.
// versions:
//   sqlc v1.26.0
// source: pricing.sql

package product

import (
	"context"

	"github.com/shopspring/decimal"
)

const createProductPricing = `-- name: CreateProductPricing :exec
INSERT INTO product_pricing (
    product_id, base_price, currency_code, discount, discounted_price, is_on_sale
) VALUES (
    $1, $2, $3, $4, $5, $6
)
`

func (q *Queries) CreateProductPricing(ctx context.Context, productID int64, basePrice decimal.Decimal, currencyCode string, discount decimal.Decimal, discountedPrice decimal.Decimal, isOnSale bool) error {
	_, err := q.db.Exec(ctx, createProductPricing,
		productID,
		basePrice,
		currencyCode,
		discount,
		discountedPrice,
		isOnSale,
	)
	return err
}

const createProductVariantPricing = `-- name: CreateProductVariantPricing :one
INSERT INTO product_variant_pricing (
    variant_id, base_price, currency_code, discount, discounted_price, is_on_sale
) VALUES (
    $1, $2, $3, $4, $5, $6
) RETURNING variant_id
`

func (q *Queries) CreateProductVariantPricing(ctx context.Context, variantID int64, basePrice decimal.Decimal, currencyCode string, discount decimal.Decimal, discountedPrice decimal.Decimal, isOnSale bool) (int64, error) {
	row := q.db.QueryRow(ctx, createProductVariantPricing,
		variantID,
		basePrice,
		currencyCode,
		discount,
		discountedPrice,
		isOnSale,
	)
	var variant_id int64
	err := row.Scan(&variant_id)
	return variant_id, err
}

const getMinMaxPricesByCategoryID = `-- name: GetMinMaxPricesByCategoryID :one
SELECT
    MIN(pp.discounted_price)::numeric AS min_price,
    MAX(pp.discounted_price)::numeric AS max_price
FROM
    products p
        JOIN
    product_pricing pp ON p.id = pp.product_id
WHERE
    p.category_id = $1
`

type GetMinMaxPricesByCategoryIDRow struct {
	MinPrice decimal.Decimal
	MaxPrice decimal.Decimal
}

func (q *Queries) GetMinMaxPricesByCategoryID(ctx context.Context, categoryID int32) (*GetMinMaxPricesByCategoryIDRow, error) {
	row := q.db.QueryRow(ctx, getMinMaxPricesByCategoryID, categoryID)
	var i GetMinMaxPricesByCategoryIDRow
	err := row.Scan(&i.MinPrice, &i.MaxPrice)
	return &i, err
}

const getMinMaxPricesByCategoryIDs = `-- name: GetMinMaxPricesByCategoryIDs :one
SELECT
    MIN(pp.discounted_price)::numeric AS min_price,
    MAX(pp.discounted_price)::numeric AS max_price
FROM
    products p
        JOIN
    product_pricing pp ON p.id = pp.product_id
WHERE
    p.category_id = ANY($1::INT[])
`

type GetMinMaxPricesByCategoryIDsRow struct {
	MinPrice decimal.Decimal
	MaxPrice decimal.Decimal
}

func (q *Queries) GetMinMaxPricesByCategoryIDs(ctx context.Context, leafcategoryids []int32) (*GetMinMaxPricesByCategoryIDsRow, error) {
	row := q.db.QueryRow(ctx, getMinMaxPricesByCategoryIDs, leafcategoryids)
	var i GetMinMaxPricesByCategoryIDsRow
	err := row.Scan(&i.MinPrice, &i.MaxPrice)
	return &i, err
}

const getProductPricingByProductID = `-- name: GetProductPricingByProductID :one
SELECT product_id, base_price, currency_code, discount, discounted_price, is_on_sale FROM product_pricing
WHERE product_id = $1
`

func (q *Queries) GetProductPricingByProductID(ctx context.Context, productID int64) (*ProductPricing, error) {
	row := q.db.QueryRow(ctx, getProductPricingByProductID, productID)
	var i ProductPricing
	err := row.Scan(
		&i.ProductID,
		&i.BasePrice,
		&i.CurrencyCode,
		&i.Discount,
		&i.DiscountedPrice,
		&i.IsOnSale,
	)
	return &i, err
}

const getProductVariantPricingByVariantID = `-- name: GetProductVariantPricingByVariantID :one
SELECT variant_id, base_price, currency_code, discount, discounted_price, is_on_sale FROM product_variant_pricing
WHERE variant_id = $1
`

func (q *Queries) GetProductVariantPricingByVariantID(ctx context.Context, variantID int64) (*ProductVariantPricing, error) {
	row := q.db.QueryRow(ctx, getProductVariantPricingByVariantID, variantID)
	var i ProductVariantPricing
	err := row.Scan(
		&i.VariantID,
		&i.BasePrice,
		&i.CurrencyCode,
		&i.Discount,
		&i.DiscountedPrice,
		&i.IsOnSale,
	)
	return &i, err
}
