using System;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;

#nullable disable

namespace Demo2.Migrations
{
    /// <inheritdoc />
    public partial class InitialCreate2 : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.EnsureSchema(
                name: "task16-09");

            migrationBuilder.CreateTable(
                name: "gender",
                schema: "task16-09",
                columns: table => new
                {
                    code = table.Column<char>(type: "character(1)", maxLength: 1, nullable: false),
                    name = table.Column<string>(type: "character varying(10)", maxLength: 10, nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("gender_pkey", x => x.code);
                });

            migrationBuilder.CreateTable(
                name: "manufacturer",
                schema: "task16-09",
                columns: table => new
                {
                    id = table.Column<int>(type: "integer", nullable: false)
                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                    name = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false),
                    startdate = table.Column<DateOnly>(type: "date", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("manufacturer_pkey", x => x.id);
                });

            migrationBuilder.CreateTable(
                name: "service",
                schema: "task16-09",
                columns: table => new
                {
                    id = table.Column<int>(type: "integer", nullable: false)
                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                    title = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false),
                    cost = table.Column<decimal>(type: "numeric(19,4)", precision: 19, scale: 4, nullable: false),
                    durationinseconds = table.Column<int>(type: "integer", nullable: false),
                    description = table.Column<string>(type: "text", nullable: true),
                    discount = table.Column<double>(type: "double precision", nullable: true),
                    mainimagepath = table.Column<string>(type: "character varying(1000)", maxLength: 1000, nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("service_pkey", x => x.id);
                });

            migrationBuilder.CreateTable(
                name: "tag",
                schema: "task16-09",
                columns: table => new
                {
                    id = table.Column<int>(type: "integer", nullable: false),
                    title = table.Column<string>(type: "character varying(30)", maxLength: 30, nullable: false),
                    color = table.Column<string>(type: "character(8)", fixedLength: true, maxLength: 8, nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("tag_pkey", x => x.id);
                });

            migrationBuilder.CreateTable(
                name: "client",
                schema: "task16-09",
                columns: table => new
                {
                    id = table.Column<int>(type: "integer", nullable: false)
                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                    firstname = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false),
                    lastname = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false),
                    patronymic = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: true),
                    birthday = table.Column<DateOnly>(type: "date", nullable: true),
                    registrationdate = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: false),
                    email = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: true),
                    phone = table.Column<string>(type: "character varying(20)", maxLength: 20, nullable: false),
                    gendercode = table.Column<char>(type: "character(1)", maxLength: 1, nullable: false),
                    photopath = table.Column<string>(type: "character varying(1000)", maxLength: 1000, nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("client_pkey", x => x.id);
                    table.ForeignKey(
                        name: "fk_client_gender",
                        column: x => x.gendercode,
                        principalSchema: "task16-09",
                        principalTable: "gender",
                        principalColumn: "code");
                });

            migrationBuilder.CreateTable(
                name: "product",
                schema: "task16-09",
                columns: table => new
                {
                    id = table.Column<int>(type: "integer", nullable: false)
                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                    title = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false),
                    cost = table.Column<decimal>(type: "numeric(19,4)", precision: 19, scale: 4, nullable: false),
                    description = table.Column<string>(type: "text", nullable: true),
                    mainimagepath = table.Column<string>(type: "character varying(1000)", maxLength: 1000, nullable: true),
                    isactive = table.Column<int>(type: "integer", nullable: false),
                    manufacturerid = table.Column<int>(type: "integer", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("product_pkey", x => x.id);
                    table.ForeignKey(
                        name: "fk_product_manufacturer",
                        column: x => x.manufacturerid,
                        principalSchema: "task16-09",
                        principalTable: "manufacturer",
                        principalColumn: "id");
                });

            migrationBuilder.CreateTable(
                name: "servicephoto",
                schema: "task16-09",
                columns: table => new
                {
                    id = table.Column<int>(type: "integer", nullable: false)
                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                    serviceid = table.Column<int>(type: "integer", nullable: false),
                    photopath = table.Column<string>(type: "character varying(1000)", maxLength: 1000, nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("servicephoto_pkey", x => x.id);
                    table.ForeignKey(
                        name: "fk_servicephoto_service",
                        column: x => x.serviceid,
                        principalSchema: "task16-09",
                        principalTable: "service",
                        principalColumn: "id");
                });

            migrationBuilder.CreateTable(
                name: "clientservice",
                schema: "task16-09",
                columns: table => new
                {
                    id = table.Column<int>(type: "integer", nullable: false)
                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                    clientid = table.Column<int>(type: "integer", nullable: false),
                    serviceid = table.Column<int>(type: "integer", nullable: false),
                    starttime = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: false),
                    comment = table.Column<string>(type: "text", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("clientservice_pkey", x => x.id);
                    table.ForeignKey(
                        name: "fk_clientservice_client",
                        column: x => x.clientid,
                        principalSchema: "task16-09",
                        principalTable: "client",
                        principalColumn: "id");
                    table.ForeignKey(
                        name: "fk_clientservice_service",
                        column: x => x.serviceid,
                        principalSchema: "task16-09",
                        principalTable: "service",
                        principalColumn: "id");
                });

            migrationBuilder.CreateTable(
                name: "tagofclient",
                schema: "task16-09",
                columns: table => new
                {
                    clientid = table.Column<int>(type: "integer", nullable: false),
                    tagid = table.Column<int>(type: "integer", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("tagofclient_pkey", x => new { x.clientid, x.tagid });
                    table.ForeignKey(
                        name: "fk_tagofclient_client",
                        column: x => x.clientid,
                        principalSchema: "task16-09",
                        principalTable: "client",
                        principalColumn: "id");
                    table.ForeignKey(
                        name: "tagofclient_tag_fk",
                        column: x => x.tagid,
                        principalSchema: "task16-09",
                        principalTable: "tag",
                        principalColumn: "id");
                });

            migrationBuilder.CreateTable(
                name: "attachedproduct",
                schema: "task16-09",
                columns: table => new
                {
                    mainproductid = table.Column<int>(type: "integer", nullable: false),
                    attachedproductid = table.Column<int>(type: "integer", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("attachedproduct_pkey", x => new { x.mainproductid, x.attachedproductid });
                    table.ForeignKey(
                        name: "fk_attachedproduct_product",
                        column: x => x.mainproductid,
                        principalSchema: "task16-09",
                        principalTable: "product",
                        principalColumn: "id");
                    table.ForeignKey(
                        name: "fk_attachedproduct_product1",
                        column: x => x.attachedproductid,
                        principalSchema: "task16-09",
                        principalTable: "product",
                        principalColumn: "id");
                });

            migrationBuilder.CreateTable(
                name: "productphoto",
                schema: "task16-09",
                columns: table => new
                {
                    id = table.Column<int>(type: "integer", nullable: false)
                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                    productid = table.Column<int>(type: "integer", nullable: false),
                    photopath = table.Column<string>(type: "character varying(1000)", maxLength: 1000, nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("productphoto_pkey", x => x.id);
                    table.ForeignKey(
                        name: "fk_productphoto_product",
                        column: x => x.productid,
                        principalSchema: "task16-09",
                        principalTable: "product",
                        principalColumn: "id");
                });

            migrationBuilder.CreateTable(
                name: "documentbyservice",
                schema: "task16-09",
                columns: table => new
                {
                    id = table.Column<int>(type: "integer", nullable: false)
                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                    clientserviceid = table.Column<int>(type: "integer", nullable: false),
                    documentpath = table.Column<string>(type: "character varying(1000)", maxLength: 1000, nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("documentbyservice_pkey", x => x.id);
                    table.ForeignKey(
                        name: "fk_documentbyservice_clientservice",
                        column: x => x.clientserviceid,
                        principalSchema: "task16-09",
                        principalTable: "clientservice",
                        principalColumn: "id");
                });

            migrationBuilder.CreateTable(
                name: "productsale",
                schema: "task16-09",
                columns: table => new
                {
                    id = table.Column<int>(type: "integer", nullable: false)
                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                    saledate = table.Column<DateTime>(type: "timestamp(6) without time zone", nullable: false),
                    productid = table.Column<int>(type: "integer", nullable: false),
                    quantity = table.Column<int>(type: "integer", nullable: false),
                    clientserviceid = table.Column<int>(type: "integer", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("productsale_pkey", x => x.id);
                    table.ForeignKey(
                        name: "fk_productsale_clientservice",
                        column: x => x.clientserviceid,
                        principalSchema: "task16-09",
                        principalTable: "clientservice",
                        principalColumn: "id");
                    table.ForeignKey(
                        name: "fk_productsale_product",
                        column: x => x.productid,
                        principalSchema: "task16-09",
                        principalTable: "product",
                        principalColumn: "id");
                });

            migrationBuilder.CreateIndex(
                name: "IX_attachedproduct_attachedproductid",
                schema: "task16-09",
                table: "attachedproduct",
                column: "attachedproductid");

            migrationBuilder.CreateIndex(
                name: "IX_client_gendercode",
                schema: "task16-09",
                table: "client",
                column: "gendercode");

            migrationBuilder.CreateIndex(
                name: "IX_clientservice_clientid",
                schema: "task16-09",
                table: "clientservice",
                column: "clientid");

            migrationBuilder.CreateIndex(
                name: "IX_clientservice_serviceid",
                schema: "task16-09",
                table: "clientservice",
                column: "serviceid");

            migrationBuilder.CreateIndex(
                name: "IX_documentbyservice_clientserviceid",
                schema: "task16-09",
                table: "documentbyservice",
                column: "clientserviceid");

            migrationBuilder.CreateIndex(
                name: "IX_product_manufacturerid",
                schema: "task16-09",
                table: "product",
                column: "manufacturerid");

            migrationBuilder.CreateIndex(
                name: "IX_productphoto_productid",
                schema: "task16-09",
                table: "productphoto",
                column: "productid");

            migrationBuilder.CreateIndex(
                name: "IX_productsale_clientserviceid",
                schema: "task16-09",
                table: "productsale",
                column: "clientserviceid");

            migrationBuilder.CreateIndex(
                name: "IX_productsale_productid",
                schema: "task16-09",
                table: "productsale",
                column: "productid");

            migrationBuilder.CreateIndex(
                name: "IX_servicephoto_serviceid",
                schema: "task16-09",
                table: "servicephoto",
                column: "serviceid");

            migrationBuilder.CreateIndex(
                name: "IX_tagofclient_tagid",
                schema: "task16-09",
                table: "tagofclient",
                column: "tagid");
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "attachedproduct",
                schema: "task16-09");

            migrationBuilder.DropTable(
                name: "documentbyservice",
                schema: "task16-09");

            migrationBuilder.DropTable(
                name: "productphoto",
                schema: "task16-09");

            migrationBuilder.DropTable(
                name: "productsale",
                schema: "task16-09");

            migrationBuilder.DropTable(
                name: "servicephoto",
                schema: "task16-09");

            migrationBuilder.DropTable(
                name: "tagofclient",
                schema: "task16-09");

            migrationBuilder.DropTable(
                name: "clientservice",
                schema: "task16-09");

            migrationBuilder.DropTable(
                name: "product",
                schema: "task16-09");

            migrationBuilder.DropTable(
                name: "tag",
                schema: "task16-09");

            migrationBuilder.DropTable(
                name: "client",
                schema: "task16-09");

            migrationBuilder.DropTable(
                name: "service",
                schema: "task16-09");

            migrationBuilder.DropTable(
                name: "manufacturer",
                schema: "task16-09");

            migrationBuilder.DropTable(
                name: "gender",
                schema: "task16-09");
        }
    }
}
