import pathlib
import json


def generate_zone(x: int, y: int, size: int) -> pathlib.Path:
    """Generates a zone of the tilemap

    :param x: X grid number
    :type x: int
    :param y: y grid number
    :type y: int
    :param size: how many tiles is the zone length
    :type size: int
    :return: Path to the zone save file
    :rtype: pathlib.Path
    """

    zone_path = pathlib.Path(
        "assets/data/zones/{}_{}.json".format(
            x,
            y
        )
    )

    zone_tilemap = []

    if y == 0:
        zone_tilemap = [[{0: 0} for i in range(size)]]

    for i in range(size):

        row = [{1: 0} for i in range(size)]
        if x == 0:
            row[0] = {0: 0}

        zone_tilemap.insert(
            i+1,
            row
        )

    with zone_path.open("w") as save:
        json.dump(zone_tilemap, save, indent=4)

    return zone_path