using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace CMSMicroservice.Infrastructure.Persistence.Migrations
{
    /// <inheritdoc />
    public partial class AddPublicMessageSystem : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "PublicMessages",
                schema: "CMS",
                columns: table => new
                {
                    Id = table.Column<long>(type: "bigint", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    Title = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: false),
                    Content = table.Column<string>(type: "nvarchar(2000)", maxLength: 2000, nullable: false),
                    Type = table.Column<int>(type: "int", nullable: false),
                    Priority = table.Column<int>(type: "int", nullable: false),
                    IsActive = table.Column<bool>(type: "bit", nullable: false, defaultValue: true),
                    StartsAt = table.Column<DateTime>(type: "datetime2", nullable: false),
                    ExpiresAt = table.Column<DateTime>(type: "datetime2", nullable: false),
                    CreatedByUserId = table.Column<long>(type: "bigint", nullable: false),
                    ViewCount = table.Column<int>(type: "int", nullable: false, defaultValue: 0),
                    LinkUrl = table.Column<string>(type: "nvarchar(500)", maxLength: 500, nullable: true),
                    LinkText = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: true),
                    Created = table.Column<DateTime>(type: "datetime2", nullable: false),
                    CreatedBy = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    LastModified = table.Column<DateTime>(type: "datetime2", nullable: true),
                    LastModifiedBy = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    IsDeleted = table.Column<bool>(type: "bit", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_PublicMessages", x => x.Id);
                });

            migrationBuilder.CreateIndex(
                name: "IX_PublicMessages_CreatedByUserId",
                schema: "CMS",
                table: "PublicMessages",
                column: "CreatedByUserId");

            migrationBuilder.CreateIndex(
                name: "IX_PublicMessages_ExpiresAt",
                schema: "CMS",
                table: "PublicMessages",
                column: "ExpiresAt");

            migrationBuilder.CreateIndex(
                name: "IX_PublicMessages_IsActive",
                schema: "CMS",
                table: "PublicMessages",
                column: "IsActive");

            migrationBuilder.CreateIndex(
                name: "IX_PublicMessages_IsActive_ExpiresAt",
                schema: "CMS",
                table: "PublicMessages",
                columns: new[] { "IsActive", "ExpiresAt" });

            migrationBuilder.CreateIndex(
                name: "IX_PublicMessages_Priority",
                schema: "CMS",
                table: "PublicMessages",
                column: "Priority");

            migrationBuilder.CreateIndex(
                name: "IX_PublicMessages_StartsAt",
                schema: "CMS",
                table: "PublicMessages",
                column: "StartsAt");

            migrationBuilder.CreateIndex(
                name: "IX_PublicMessages_Type",
                schema: "CMS",
                table: "PublicMessages",
                column: "Type");
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "PublicMessages",
                schema: "CMS");
        }
    }
}
