// Licensed to Timothy Schenk under the GNU AGPL Version 3 License.

#nullable disable

namespace Server.DB.Migrations;
using Microsoft.EntityFrameworkCore.Migrations;

/// <inheritdoc />
public partial class CharacterDataDraft : Migration
{
    /// <inheritdoc />
    protected override void Up(MigrationBuilder migrationBuilder)
    {
        migrationBuilder.AlterColumn<string>(
            name: "Username",
            table: "Accounts",
            type: "varchar(20)",
            nullable: true,
            oldClrType: typeof(string),
            oldType: "varchar(20)");

        migrationBuilder.AlterColumn<byte[]>(
            name: "Salt",
            table: "Accounts",
            type: "bytea",
            nullable: true,
            oldClrType: typeof(byte[]),
            oldType: "bytea");

        migrationBuilder.AlterColumn<byte[]>(
            name: "Password",
            table: "Accounts",
            type: "bytea",
            nullable: true,
            oldClrType: typeof(byte[]),
            oldType: "bytea");

        migrationBuilder.AlterColumn<string>(
            name: "Email",
            table: "Accounts",
            type: "text",
            nullable: true,
            oldClrType: typeof(string),
            oldType: "text");

        migrationBuilder.CreateTable(
            name: "Characters",
            columns: table => new
            {
                Id = table.Column<Guid>(type: "uuid", nullable: false),
                ServerId = table.Column<byte>(type: "smallint", nullable: false),
                AccountId = table.Column<Guid>(type: "uuid", nullable: false),
                MapId = table.Column<int>(type: "integer", nullable: false),
                Name = table.Column<string>(type: "varchar(20)", nullable: true),
                LastXCoordinate = table.Column<short>(type: "smallint", nullable: false),
                LastYCoordinate = table.Column<short>(type: "smallint", nullable: false),
                PvPLevel = table.Column<byte>(type: "smallint", nullable: false),
                Gender = table.Column<byte>(type: "smallint", nullable: false),
                Experience = table.Column<long>(type: "bigint", nullable: false),
                Level = table.Column<byte>(type: "smallint", nullable: false)
            },
            constraints: table =>
            {
                table.PrimaryKey("PK_Characters", x => x.Id);
                table.ForeignKey(
                    name: "FK_Characters_Accounts_AccountId",
                    column: x => x.AccountId,
                    principalTable: "Accounts",
                    principalColumn: "Id",
                    onDelete: ReferentialAction.Cascade);
            });

        migrationBuilder.CreateIndex(
            name: "IX_Characters_AccountId",
            table: "Characters",
            column: "AccountId");
    }

    /// <inheritdoc />
    protected override void Down(MigrationBuilder migrationBuilder)
    {
        migrationBuilder.DropTable(
            name: "Characters");

        migrationBuilder.AlterColumn<string>(
            name: "Username",
            table: "Accounts",
            type: "varchar(20)",
            nullable: false,
            defaultValue: "",
            oldClrType: typeof(string),
            oldType: "varchar(20)",
            oldNullable: true);

        migrationBuilder.AlterColumn<byte[]>(
            name: "Salt",
            table: "Accounts",
            type: "bytea",
            nullable: false,
            defaultValue: Array.Empty<byte>(),
            oldClrType: typeof(byte[]),
            oldType: "bytea",
            oldNullable: true);

        migrationBuilder.AlterColumn<byte[]>(
            name: "Password",
            table: "Accounts",
            type: "bytea",
            nullable: false,
            defaultValue: Array.Empty<byte>(),
            oldClrType: typeof(byte[]),
            oldType: "bytea",
            oldNullable: true);

        migrationBuilder.AlterColumn<string>(
            name: "Email",
            table: "Accounts",
            type: "text",
            nullable: false,
            defaultValue: "",
            oldClrType: typeof(string),
            oldType: "text",
            oldNullable: true);
    }
}