-- schema.sql
-- Datenbank-Schema für 3D-Druck Materialdatenbank

CREATE TABLE materials (
    id INT AUTO_INCREMENT PRIMARY KEY,
    code VARCHAR(50) NOT NULL,
    name VARCHAR(150) NOT NULL,
    short_desc VARCHAR(255) NULL,
    properties TEXT NULL,
    tg_celsius DECIMAL(5,1) NULL,
    nozzle_req VARCHAR(150) NULL,
    plate_req VARCHAR(150) NULL,
    extra_req VARCHAR(255) NULL,
    application TEXT NULL,
    kid_safety ENUM('safe','limited','no') DEFAULT 'limited',
    emission ENUM('low','medium','high') DEFAULT 'low',
    is_active TINYINT(1) DEFAULT 1,
    UNIQUE KEY uq_material_code (code)
);

CREATE TABLE printers (
    id INT AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(150) NOT NULL,
    brand VARCHAR(100) NULL,
    model_code VARCHAR(100) NULL,
    max_nozzle_temp INT NULL,
    max_bed_temp INT NULL,
    chamber TINYINT(1) DEFAULT 0,
    build_volume VARCHAR(50) NULL,
    notes TEXT NULL,
    is_active TINYINT(1) DEFAULT 1
);

CREATE TABLE printer_material_support (
    id INT AUTO_INCREMENT PRIMARY KEY,
    printer_id INT NOT NULL,
    material_id INT NOT NULL,
    support_level ENUM('full','partial','with_addon','no') NOT NULL DEFAULT 'no',
    partial_reason VARCHAR(255) NULL,
    extra_info VARCHAR(255) NULL,
    updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    CONSTRAINT fk_pms_printer FOREIGN KEY (printer_id) REFERENCES printers(id) ON DELETE CASCADE,
    CONSTRAINT fk_pms_material FOREIGN KEY (material_id) REFERENCES materials(id) ON DELETE CASCADE,
    UNIQUE KEY uq_printer_material (printer_id, material_id)
);
