using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Meezi.Infrastructure.Data.Migrations
{
    /// <inheritdoc />
    public partial class AddCafeReviews : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.AddColumn<string>(
                name: "CoverImageUrl",
                table: "Cafes",
                type: "text",
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "Description",
                table: "Cafes",
                type: "text",
                nullable: true);

            migrationBuilder.CreateTable(
                name: "CafeReviews",
                columns: table => new
                {
                    Id = table.Column<string>(type: "text", nullable: false),
                    CafeId = table.Column<string>(type: "text", nullable: false),
                    AuthorName = table.Column<string>(type: "character varying(200)", maxLength: 200, nullable: false),
                    AuthorPhone = table.Column<string>(type: "text", nullable: true),
                    Rating = table.Column<int>(type: "integer", nullable: false),
                    Comment = table.Column<string>(type: "text", nullable: true),
                    OwnerReply = table.Column<string>(type: "text", nullable: true),
                    OwnerRepliedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
                    CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
                    DeletedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_CafeReviews", x => x.Id);
                    table.ForeignKey(
                        name: "FK_CafeReviews_Cafes_CafeId",
                        column: x => x.CafeId,
                        principalTable: "Cafes",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_CafeReviews_CafeId_CreatedAt",
                table: "CafeReviews",
                columns: new[] { "CafeId", "CreatedAt" });
        }

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

            migrationBuilder.DropColumn(
                name: "CoverImageUrl",
                table: "Cafes");

            migrationBuilder.DropColumn(
                name: "Description",
                table: "Cafes");
        }
    }
}
