# generated by datamodel-codegen:
#   filename:  SegmentationRequest-schema.json
#   timestamp: 2025-11-20T19:48:15+00:00

# Procedure:
# 1. Generate from schema:
#  datamodel-codegen \
# --input ../cimg-api/src/main/resources/schema/SegmentationRequest-schema.json \
# --input-file-type jsonschema \
# --output src/orgjax/pyjit/model/crop.py \
# --output-model-type dataclasses.dataclass
#
# 2. Remove classes such as StorageKey and Protocol, instead import them from dao.py
# 3. Change the main request to inherit from AbstractRequest
# 4. Make sure that the defaults from ../templates.py are the same.


from __future__ import annotations

from dataclasses import dataclass, field
from enum import Enum
from typing import Any, Dict, List, Optional, Union
from ..dao import StorageKey, AbstractRequest
from . import Info


@dataclass
class ParticleSettings:
    min: float = 1200000
    max: float = 2147483647
    cMin: float = 0.1
    cMax: float = 1.0
    hardBounds: bool = True


@dataclass
class ImagePreprocessSettings:
    rollingBallRadius: int = 50
    sigma: float = 100
    accuracy: float = 0.002
    autoThreshold: Optional[str] = "Otsu"


class Order(Enum):
    NONE = "NONE"
    ROWS = "ROWS"
    COLUMS = "COLUMS"


@dataclass
class Point:
    x: float
    y: float


@dataclass
class Dimension:
    width: float
    height: float


class Type(Enum):
    FeatureCollection = "FeatureCollection"


class Type1(Enum):
    name = "name"
    link = "link"


@dataclass
class Object:
    pass


class Type2(Enum):
    Feature = "Feature"


class Type3(Enum):
    Polygon = "Polygon"


class Type4(Enum):
    MultiPolygon = "MultiPolygon"


class Type5(Enum):
    Point = "Point"


class Type6(Enum):
    LineString = "LineString"


class Type7(Enum):
    MultiLineString = "MultiLineString"


class Type8(Enum):
    GeometryCollection = "GeometryCollection"


class Order1(Enum):
    IMAGE = "IMAGE"
    GRAPH = "GRAPH"


@dataclass
class TileConfiguration:
    clip: bool = True
    alwaysTile: bool= False
    expandCroppedFiles: bool = True
    tileSize: Optional[List[int]] = field(default_factory=lambda: [4096, 4096])
    order: Optional[Order1] = Order1.IMAGE
    cropFillColor: Optional[List[int]] = None


@dataclass
class Crs:
    type: Optional[Type1] = None
    properties: Optional[Dict[str, Object]] = None


@dataclass
class Polygon1:
    type: Type3
    crs: Optional[Crs] = None
    bbox: Optional[List[float]] = None
    coordinates: Optional[List[List]] = None


@dataclass
class MultiPolygon:
    type: Type4
    crs: Optional[Crs] = None
    bbox: Optional[List[float]] = None
    coordinates: Optional[List[List[List]]] = None


@dataclass
class Point1:
    type: Type5
    crs: Optional[Crs] = None
    bbox: Optional[List[float]] = None
    coordinates: Optional[Any] = None


@dataclass
class LineString:
    type: Type6
    crs: Optional[Crs] = None
    bbox: Optional[List[float]] = None
    coordinates: Optional[List] = None


@dataclass
class MultiLineString:
    type: Type7
    crs: Optional[Crs] = None
    bbox: Optional[List[float]] = None
    coordinates: Optional[List[List]] = None


MultiPoint = LineString


@dataclass
class RegionSettings:
    minimumAspectRatio: float = 0.15
    margin: int = 10
    findRegions: bool = True
    showRegions: bool = False
    manualRegionResolution: int = 0
    manualRegions: Optional[List[Polygon]] = field(default_factory=lambda: [])
    userRegions: Optional[FeatureCollection] = None
    generateProofImage: bool = True
    generatePreviews: bool = True
    previewSize: int = 2048
    zip: bool = True
    saveAsJson: bool = True
    fontSize: int= 160
    cropFoundRegionsAsRectangles: bool= True
    forceSquare: bool= False
    cropAsGreyScale: bool= False
    reference: Optional[Rectangle] = None
    order: Optional[Order] = Order.ROWS


@dataclass
class Rectangle:
    x: float
    y: float
    width: float
    height: float
    empty: bool
    minX: float
    minY: float
    maxX: float
    maxY: float
    centerX: float
    centerY: float
    bounds2D: Optional[Rectangle2D] = None
    location: Optional[Point] = None
    size: Optional[Dimension] = None


@dataclass
class Rectangle2D:
    x: float
    y: float
    width: float
    height: float
    minX: float
    minY: float
    maxX: float
    maxY: float
    centerX: float
    centerY: float
    empty: bool
    bounds2D: Optional[Rectangle2D] = None
    bounds: Optional[Rectangle] = None


@dataclass
class Polygon:
    npoints: int
    xpoints: Optional[List[int]] = None
    ypoints: Optional[List[int]] = None
    bounds: Optional[Rectangle] = None
    bounds2D: Optional[Rectangle2D] = None
    boundingBox: Optional[Rectangle] = None


@dataclass
class FeatureCollection:
    type: Type
    crs: Optional[Crs] = None
    bbox: Optional[List[float]] = None
    features: Optional[List[Feature]] = None


@dataclass
class Feature:
    type: Type2
    crs: Optional[Crs] = None
    bbox: Optional[List[float]] = None
    properties: Optional[Dict[str, Object]] = None
    geometry: Optional[
        Union[
            Feature,
            Polygon1,
            MultiPolygon,
            FeatureCollection,
            Point1,
            MultiPoint,
            MultiLineString,
            LineString,
            GeometryCollection,
        ]
    ] = None
    id: Optional[str] = None


@dataclass
class GeometryCollection:
    type: Type8
    crs: Optional[Crs] = None
    bbox: Optional[List[float]] = None
    geometries: Optional[
        List[
            Union[
                Feature,
                Polygon1,
                MultiPolygon,
                FeatureCollection,
                Point1,
                MultiPoint,
                MultiLineString,
                LineString,
                GeometryCollection,
            ]
        ]
    ] = None

@dataclass
class SegmentationRequest(AbstractRequest):
    
    info: Optional[Info] = field(default_factory=lambda: Info.CROP)
    
    bytesPerPixel: int = 0
    findResolution: int = -2147483648
    optimumFindSize: int = 16000000
    cropResolution: int = 0
    saveRequest: bool= True
    imageJPlugin: bool = False
    image: Optional[str] = None
    outputDir: Optional[StorageKey] = None
    cropIndices: Optional[List[int]] = None
    particleSettings: Optional[ParticleSettings] = field(default_factory=ParticleSettings)
    imagePreprocess: Optional[ImagePreprocessSettings] = field(default_factory=ImagePreprocessSettings)
    regionSettings: Optional[RegionSettings] = field(default_factory=RegionSettings)
    prefix: Optional[str] = ""
    tileConfiguration: Optional[TileConfiguration] = field(default_factory=TileConfiguration)
    version: Optional[str] = None
