CREATE TABLE IF NOT EXISTS users (
    id SERIAL PRIMARY KEY,
    name VARCHAR(255) NOT NULL,
    email VARCHAR(255) UNIQUE NOT NULL,
    password_hash TEXT NOT NULL,
    reset_token TEXT NULL,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

CREATE TABLE IF NOT EXISTS categories(
    id serial PRIMARY KEY,
    name VARCHAR(255) NOT NULL,
    description VARCHAR(255) NOT NULL
);

CREATE TABLE IF NOT EXISTS sneakers(
    id SERIAL PRIMARY KEY,
    name VARCHAR(255) NOT NULL,
    description VARCHAR(255) NOT NULL,
    cost DECIMAL(10,2) NOT NULL,
    discount INTEGER NOT NULL CHECK (discount >= 0 AND discount <= 100),
    photo VARCHAR(255) NOT NULL,
    gender CHAR(1) NOT NULL CHECK (gender IN ('M', 'F', 'U')),
    bootSize INTEGER NOT NULL,
    categoryid INTEGER NOT NULL,
    FOREIGN KEY (categoryid) REFERENCES categories(id) ON DELETE CASCADE
);

INSERT INTO categories (name, description)
VALUES ('tennis', 'for tennis');

INSERT INTO categories (name, description)
VALUES ('outdoor', 'for walking');

INSERT INTO categories (name, description)
VALUES ('football', 'for football');

INSERT INTO sneakers (name, description, cost, discount, photo, gender, bootSize, categoryid)
VALUES ('Adidas', 'fast', 120.50, 10, 'https://i8.amplience.net/i/jpl/jd_619310_a?qlt=92', 'M', 42, 3);

INSERT INTO sneakers (name, description, cost, discount, photo, gender, bootSize, categoryid)
VALUES ('Nike Air Max', 'Comfortable running shoes', 140, 40, 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRe7ZbQ92u1JD-JgD4Kkhkju83p_uvKelP5jw&s', 'F', 39, 2);

INSERT INTO sneakers (name, description, cost, discount, photo, gender, bootSize, categoryid)
VALUES ('Puma', 'fast too', 80.12, 80, 'https://img01.ztat.net/article/spp-media-p1/c6ebc4348bd34d9fa4235a82453230fe/3c034c2c43b94d879d41d33d0eb18e14.jpg?imwidth=1800&filter=packshot', 'U', 41, 1);