-- CreateEnum
CREATE TYPE "TournamentStatus" AS ENUM ('ABERTO', 'PREPARANDO', 'EM ANDAMENTO', 'FINALIZADO');

-- CreateEnum
CREATE TYPE "tournamentPrivacy" AS ENUM ('PUBLIC', 'PRIVATE');

-- CreateEnum
CREATE TYPE "FoulCard" AS ENUM ('RED', 'YELLOW');

-- AlterTable
ALTER TABLE "teams" ADD COLUMN     "tournament_id" INTEGER;

-- CreateTable
CREATE TABLE "Goals" (
    "goal_id" SERIAL NOT NULL,
    "match_id" INTEGER NOT NULL,
    "goal_team" TEXT NOT NULL,
    "goal_player" TEXT NOT NULL,
    "goal_time" TIMESTAMP(3) NOT NULL,

    CONSTRAINT "Goals_pkey" PRIMARY KEY ("goal_id")
);

-- CreateTable
CREATE TABLE "Foals" (
    "foul_id" SERIAL NOT NULL,
    "match_id" INTEGER NOT NULL,
    "foul_player" TEXT NOT NULL,
    "foul_type" TEXT NOT NULL,
    "foul_card" "FoulCard" NOT NULL,
    "foul_time" TIMESTAMP(3) NOT NULL,

    CONSTRAINT "Foals_pkey" PRIMARY KEY ("foul_id")
);

-- CreateTable
CREATE TABLE "Matches" (
    "match_id" SERIAL NOT NULL,
    "tournament_id" INTEGER NOT NULL,
    "home_team" TEXT NOT NULL,
    "visitors_team" TEXT NOT NULL,
    "match_status" TEXT NOT NULL,
    "match_date" TIMESTAMP(3) NOT NULL,
    "match_address" TEXT NOT NULL,
    "created_at" TIMESTAMP(3) NOT NULL,

    CONSTRAINT "Matches_pkey" PRIMARY KEY ("match_id")
);

-- CreateTable
CREATE TABLE "Tournament" (
    "tournament_id" SERIAL NOT NULL,
    "tournament_title" TEXT NOT NULL,
    "tournament_invite" TEXT NOT NULL,
    "tournamentPrivacy" "tournamentPrivacy" NOT NULL DEFAULT 'PUBLIC',
    "tournament_address" TEXT NOT NULL,
    "tournament_subscribe_time" TIMESTAMP(3) NOT NULL,
    "tournament_matchmaking_time" TIMESTAMP(3) NOT NULL,
    "tournament_status" "TournamentStatus" NOT NULL DEFAULT 'ABERTO',
    "tournament_background" TEXT,
    "tournament_description" TEXT,
    "owner_id" INTEGER NOT NULL,
    "created_at" TIMESTAMP(3) NOT NULL,

    CONSTRAINT "Tournament_pkey" PRIMARY KEY ("tournament_id")
);

-- AddForeignKey
ALTER TABLE "teams" ADD CONSTRAINT "teams_tournament_id_fkey" FOREIGN KEY ("tournament_id") REFERENCES "Tournament"("tournament_id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Goals" ADD CONSTRAINT "Goals_match_id_fkey" FOREIGN KEY ("match_id") REFERENCES "Matches"("match_id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Foals" ADD CONSTRAINT "Foals_match_id_fkey" FOREIGN KEY ("match_id") REFERENCES "Matches"("match_id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Matches" ADD CONSTRAINT "Matches_tournament_id_fkey" FOREIGN KEY ("tournament_id") REFERENCES "Tournament"("tournament_id") ON DELETE RESTRICT ON UPDATE CASCADE;
