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

#nullable disable

namespace DeepDrftData.Migrations
{
    /// <inheritdoc />
    public partial class AddPlayShareTelemetry : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "play_counter",
                columns: table => new
                {
                    id = table.Column<long>(type: "bigint", nullable: false)
                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                    track_id = table.Column<long>(type: "bigint", nullable: false),
                    partial_count = table.Column<long>(type: "bigint", nullable: false, defaultValue: 0L),
                    sampled_count = table.Column<long>(type: "bigint", nullable: false, defaultValue: 0L),
                    complete_count = table.Column<long>(type: "bigint", nullable: false, defaultValue: 0L)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_play_counter", x => x.id);
                });

            migrationBuilder.CreateTable(
                name: "play_event",
                columns: table => new
                {
                    id = table.Column<long>(type: "bigint", nullable: false)
                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                    track_entry_key = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false),
                    release_id = table.Column<long>(type: "bigint", nullable: true),
                    bucket = table.Column<string>(type: "character varying(20)", maxLength: 20, nullable: false),
                    anon_id = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: true),
                    created_at = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_play_event", x => x.id);
                });

            migrationBuilder.CreateTable(
                name: "share_event",
                columns: table => new
                {
                    id = table.Column<long>(type: "bigint", nullable: false)
                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                    target_type = table.Column<string>(type: "character varying(20)", maxLength: 20, nullable: false),
                    target_key = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false),
                    channel = table.Column<string>(type: "character varying(20)", maxLength: 20, nullable: false),
                    anon_id = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: true),
                    created_at = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_share_event", x => x.id);
                });

            migrationBuilder.CreateIndex(
                name: "IX_play_counter_track_id",
                table: "play_counter",
                column: "track_id",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_play_event_anon_id",
                table: "play_event",
                column: "anon_id");

            migrationBuilder.CreateIndex(
                name: "IX_play_event_release_id",
                table: "play_event",
                column: "release_id");

            migrationBuilder.CreateIndex(
                name: "IX_play_event_track_entry_key",
                table: "play_event",
                column: "track_entry_key");

            migrationBuilder.CreateIndex(
                name: "IX_share_event_anon_id",
                table: "share_event",
                column: "anon_id");

            migrationBuilder.CreateIndex(
                name: "IX_share_event_target_key",
                table: "share_event",
                column: "target_key");
        }

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

            migrationBuilder.DropTable(
                name: "play_event");

            migrationBuilder.DropTable(
                name: "share_event");
        }
    }
}
