-- Ürünler tablosu (Yem, Tüp vb.)
CREATE TABLE IF NOT EXISTS products (
    id INT AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(100) NOT NULL,
    category ENUM('yem', 'tup', 'diger') NOT NULL,
    price DECIMAL(10, 2) NOT NULL,
    unit VARCHAR(20) DEFAULT 'adet',
    description TEXT,
    stock_quantity INT DEFAULT 0,
    is_active BOOLEAN DEFAULT TRUE,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

-- Satışlar tablosu
CREATE TABLE IF NOT EXISTS sales (
    id INT AUTO_INCREMENT PRIMARY KEY,
    customer_id INT NOT NULL,
    collector_id INT NOT NULL,
    product_id INT NOT NULL,
    quantity DECIMAL(10, 2) NOT NULL,
    unit_price DECIMAL(10, 2) NOT NULL,
    total_price DECIMAL(10, 2) NOT NULL,
    sale_date DATE NOT NULL,
    notes TEXT,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    FOREIGN KEY (customer_id) REFERENCES customers(id) ON DELETE CASCADE,
    FOREIGN KEY (collector_id) REFERENCES users(id) ON DELETE CASCADE,
    FOREIGN KEY (product_id) REFERENCES products(id) ON DELETE CASCADE
);

-- Örnek ürünler ekle
INSERT INTO products (name, category, price, unit, description, stock_quantity) VALUES
('A Tipi Yem (50 kg)', 'yem', 850.00, 'çuval', 'Süt inekleri için yüksek proteinli yem', 100),
('B Tipi Yem (50 kg)', 'yem', 750.00, 'çuval', 'Standart yem', 150),
('C Tipi Yem (25 kg)', 'yem', 400.00, 'çuval', 'Ekonomik yem', 80),
('Süt Tüpü (40 lt)', 'tup', 350.00, 'adet', '40 litrelik süt tüpü', 50),
('Süt Tüpü (25 lt)', 'tup', 250.00, 'adet', '25 litrelik süt tüpü', 60),
('Mineral Takviyesi', 'diger', 120.00, 'kg', 'Hayvan için mineral takviyesi', 200);
