# -*- coding: utf-8 -*-
"""
Server-side copy of the price / product facts.

WHY THIS FILE EXISTS
--------------------
The browser posts only *what the customer chose* (quantity + delivery area).
It never posts money. Every taka figure stored against an order is calculated
here, on the server, so a customer cannot edit the page and order the product
for 1 taka.

KEEP IN SYNC
------------
The numbers below must match `const CONFIG = { ... }` inside
templates/index.html. If you change a price on the page, change it here too.
"""

PRODUCT_NAME = 'ইলেকট্রিক হট ওয়াটার ব্যাগ'
PRODUCT_NAME_EN = 'Electric Hot Water Bag'
PRODUCT_SKU = 'EL-HWB-01'

REGULAR_PRICE = 299
OFFER_PRICE = 299

DELIVERY_INSIDE = 60
DELIVERY_OUTSIDE = 100
FREE_DELIVERY_OVER = 0          # 0 = free delivery is switched off

MIN_QTY = 1
MAX_QTY = 10

GIFT = ''                       # '' = no free gift on this product
GIFT_SIZES = []

# ---------------------------------------------------------------------------
# COLOURS
# Each row is (value stored, what the customer reads, what you read in the
# admin). The value must match `colors[].value` in templates/index.html.
# Delete a row here AND there to stop selling that colour; empty the list in
# both places and the colour picker disappears completely.
# ---------------------------------------------------------------------------
COLORS = [
    ('grey',   'ধূসর',   'Grey'),
    ('purple', 'বেগুনি', 'Purple'),
    ('brown',  'বাদামি', 'Brown'),
    ('pink',   'গোলাপি', 'Pink'),
    ('red',    'লাল',    'Red'),
]

COLOR_VALUES = [c[0] for c in COLORS]
COLOR_CHOICES = [(c[0], c[2]) for c in COLORS]   # English, for the admin


def delivery_charge(subtotal, area):
    """Delivery charge in taka for a subtotal and an area ('inside'/'outside')."""
    if FREE_DELIVERY_OVER > 0 and subtotal >= FREE_DELIVERY_OVER:
        return 0
    return DELIVERY_INSIDE if area == 'inside' else DELIVERY_OUTSIDE


def quote(quantity, area):
    """Return the full money breakdown for an order. Never trusts the client."""
    unit = OFFER_PRICE
    subtotal = unit * quantity
    delivery = delivery_charge(subtotal, area)
    return {
        'unit_price': unit,
        'subtotal': subtotal,
        'delivery_charge': delivery,
        'total': subtotal + delivery,
    }
