using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace DatabaseImplement.Migrations
{
    /// <inheritdoc />
    public partial class sellproducts : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.AddColumn<Guid>(
                name: "UserId",
                table: "Sells",
                type: "uuid",
                nullable: true);

            migrationBuilder.CreateTable(
                name: "SellProducts",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    SellId = table.Column<Guid>(type: "uuid", nullable: false),
                    ProductId = table.Column<Guid>(type: "uuid", nullable: false),
                    Count = table.Column<int>(type: "integer", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_SellProducts", x => x.Id);
                    table.ForeignKey(
                        name: "FK_SellProducts_Products_ProductId",
                        column: x => x.ProductId,
                        principalTable: "Products",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_SellProducts_Sells_SellId",
                        column: x => x.SellId,
                        principalTable: "Sells",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "SupplyDocs",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    Name = table.Column<string>(type: "text", nullable: false),
                    SupplyId = table.Column<Guid>(type: "uuid", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_SupplyDocs", x => x.Id);
                });

            migrationBuilder.CreateIndex(
                name: "IX_Sells_UserId",
                table: "Sells",
                column: "UserId");

            migrationBuilder.CreateIndex(
                name: "IX_SellProducts_ProductId",
                table: "SellProducts",
                column: "ProductId");

            migrationBuilder.CreateIndex(
                name: "IX_SellProducts_SellId",
                table: "SellProducts",
                column: "SellId");

            migrationBuilder.AddForeignKey(
                name: "FK_Sells_Users_UserId",
                table: "Sells",
                column: "UserId",
                principalTable: "Users",
                principalColumn: "Id");
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_Sells_Users_UserId",
                table: "Sells");

            migrationBuilder.DropTable(
                name: "SellProducts");

            migrationBuilder.DropTable(
                name: "SupplyDocs");

            migrationBuilder.DropIndex(
                name: "IX_Sells_UserId",
                table: "Sells");

            migrationBuilder.DropColumn(
                name: "UserId",
                table: "Sells");
        }
    }
}
