-- Add UUID extension
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";

CREATE TABLE IF NOT EXISTS public.NATION (
    nation_id SERIAL UNIQUE,
    nation_name VARCHAR(50) NOT NULL,
    PRIMARY KEY (nation_id)
);

CREATE TABLE IF NOT EXISTS public.PERSON (
    person_id uuid UNIQUE NOT NULL DEFAULT uuid_generate_v4(),
    person_firstname VARCHAR(36),
    person_lastname VARCHAR(36),
    person_age INTEGER DEFAULT 0 CHECK (person_age >= 0),
    alive BOOLEAN NOT NULL DEFAULT true,
    nation_id INTEGER REFERENCES public.NATION(nation_id) ON UPDATE CASCADE,
    PRIMARY KEY (person_id)
);

CREATE TABLE IF NOT EXISTS public.WORKORDER (
    wo_id uuid UNIQUE NOT NULL DEFAULT uuid_generate_v4(),
    wo_description TEXT,
    wo_complete BOOLEAN NOT NULL DEFAULT false,
    person_id uuid NOT NULL REFERENCES public.PERSON(person_id) ON UPDATE CASCADE,
    PRIMARY KEY (wo_id)
);