package cz.jzitnik.game.entities.items.registry.mobs;

import cz.jzitnik.game.SpriteLoader;
import cz.jzitnik.game.annotations.EntityRegistry;
import cz.jzitnik.game.entities.Block;
import cz.jzitnik.game.mobs.services.sheep.SheepData;
import cz.jzitnik.game.mobs.services.sheep.SheepVariant;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Random;

import static cz.jzitnik.game.sprites.Sheep.SheepState.*;

@EntityRegistry("sheep")
public class Sheep extends Block {
    @Getter
    @AllArgsConstructor
    private static class SheepDTO {
        private cz.jzitnik.game.sprites.Sheep.SheepState state;
        private SheepVariant variant;
    }

    private SheepDTO getSheep() {
        Random random = new Random();
        int num = random.nextInt(100);

        if (num < 1) {
            return new SheepDTO(PINK_RIGHT, SheepVariant.PINK);
        }

        if (num < 4) {
            return new SheepDTO(BROWN_RIGHT, SheepVariant.BROWN);
        }

        if (num < 15) {
            int num1 = random.nextInt(3);
            return switch (num1) {
                case 0 -> new SheepDTO(LIGHT_GRAY_RIGHT, SheepVariant.LIGHT_GRAY);
                case 1 -> new SheepDTO(GRAY_RIGHT, SheepVariant.GRAY);
                case 2 -> new SheepDTO(BLACK_RIGHT, SheepVariant.BLACK);
                default -> throw new IllegalStateException("Unexpected value: " + num1);
            };
        }

        return new SheepDTO(WHITE_RIGHT, SheepVariant.WHITE);
    }

    public Sheep() {
        super("sheep", SpriteLoader.SPRITES.SHEEP);
        var dto = getSheep();
        setMob(true);
        setGhost(true);
        setSpriteState(dto.getState());
        setMineable(false);
        setData(new SheepData(dto.getVariant()));
        setHp(8);
    }
}
