196 lines
5.2 KiB
Plaintext
196 lines
5.2 KiB
Plaintext
// Season & Cycle Management Domain
|
|
// Contains Season planning, PlotSeason tracking, and seasonal analytics
|
|
|
|
// Season-specific Enums
|
|
enum SeasonType {
|
|
WET_SEASON
|
|
DRY_SEASON
|
|
TRANSITION
|
|
YEAR_ROUND
|
|
SPRING
|
|
SUMMER
|
|
FALL
|
|
WINTER
|
|
}
|
|
|
|
enum PlantingStatus {
|
|
PLANNED
|
|
PLANTED
|
|
GROWING
|
|
FLOWERING
|
|
FRUITING
|
|
HARVESTING
|
|
HARVESTED
|
|
FAILED
|
|
ABANDONED
|
|
}
|
|
|
|
// Season Models
|
|
model Season {
|
|
id String @id @default(cuid())
|
|
name String // e.g., "Wet Season 2024", "Dry Season 2024"
|
|
seasonType SeasonType
|
|
year Int
|
|
|
|
// Timeline
|
|
startDate DateTime
|
|
endDate DateTime
|
|
|
|
// Weather characteristics
|
|
avgRainfall Decimal? // mm
|
|
avgTemperature Float? // celsius
|
|
avgHumidity Decimal? // percentage
|
|
|
|
// Agricultural phases
|
|
plantingStart DateTime?
|
|
plantingEnd DateTime?
|
|
growingStart DateTime?
|
|
growingEnd DateTime?
|
|
harvestStart DateTime?
|
|
harvestEnd DateTime?
|
|
|
|
// Region and scope
|
|
region String?
|
|
province String?
|
|
country String @default("Indonesia")
|
|
|
|
// Crop recommendations
|
|
recommendedCrops String[] // suitable crops for this season
|
|
notRecommendedCrops String[] // crops to avoid
|
|
|
|
// Market expectations
|
|
expectedDemand DemandLevel?
|
|
priceOutlook PriceTrend?
|
|
marketNotes String?
|
|
|
|
// Agricultural activities
|
|
activities Json? // structured data for farming activities
|
|
|
|
// Status
|
|
isActive Boolean @default(true)
|
|
isCurrent Boolean @default(false)
|
|
|
|
description String?
|
|
notes String?
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
|
|
// Relations
|
|
plots PlotSeason[]
|
|
harvests SeasonHarvest[]
|
|
weatherData SeasonWeather[]
|
|
|
|
@@unique([seasonType, year, region])
|
|
@@index([seasonType, year])
|
|
@@index([region])
|
|
@@index([startDate, endDate])
|
|
@@index([isActive])
|
|
@@index([isCurrent])
|
|
@@map("seasons")
|
|
}
|
|
|
|
model PlotSeason {
|
|
id String @id @default(cuid())
|
|
plotId String
|
|
seasonId String
|
|
productId String?
|
|
variantId String?
|
|
|
|
// Planting details
|
|
plantedDate DateTime?
|
|
plantedArea Decimal? // hectares actually planted
|
|
seedVariety String?
|
|
|
|
// Expected outcomes
|
|
expectedYield Decimal? // kg per hectare
|
|
expectedHarvest Decimal? // total kg expected
|
|
expectedHarvestDate DateTime?
|
|
|
|
// Actual outcomes
|
|
actualYield Decimal? // kg per hectare
|
|
actualHarvest Decimal? // total kg harvested
|
|
actualHarvestDate DateTime?
|
|
|
|
status PlantingStatus @default(PLANNED)
|
|
notes String?
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
|
|
// Relations
|
|
plot Plot @relation(fields: [plotId], references: [id])
|
|
season Season @relation(fields: [seasonId], references: [id])
|
|
product Product? @relation(fields: [productId], references: [id])
|
|
variant ProductVariant? @relation(fields: [variantId], references: [id])
|
|
|
|
@@unique([plotId, seasonId])
|
|
@@index([plotId, seasonId])
|
|
@@index([status])
|
|
@@index([plantedDate])
|
|
@@index([productId, variantId])
|
|
@@map("plot_seasons")
|
|
}
|
|
|
|
model SeasonHarvest {
|
|
id String @id @default(cuid())
|
|
seasonId String
|
|
farmerId String
|
|
productId String
|
|
variantId String?
|
|
|
|
totalQuantity Decimal
|
|
averageQuality QualityGrade
|
|
totalValue Decimal
|
|
|
|
harvestCount Int @default(1)
|
|
firstHarvest DateTime
|
|
lastHarvest DateTime?
|
|
|
|
notes String?
|
|
createdAt DateTime @default(now())
|
|
|
|
// Relations
|
|
season Season @relation(fields: [seasonId], references: [id])
|
|
farmer Farmer @relation(fields: [farmerId], references: [id])
|
|
product Product @relation(fields: [productId], references: [id])
|
|
variant ProductVariant? @relation(fields: [variantId], references: [id])
|
|
|
|
@@index([seasonId, farmerId])
|
|
@@index([productId, variantId])
|
|
@@index([firstHarvest])
|
|
@@index([averageQuality])
|
|
@@map("season_harvests")
|
|
}
|
|
|
|
model SeasonWeather {
|
|
id String @id @default(cuid())
|
|
seasonId String
|
|
region String
|
|
|
|
// Aggregated weather data
|
|
totalRainfall Decimal? // mm
|
|
avgTemperature Float? // celsius
|
|
minTemperature Float? // celsius
|
|
maxTemperature Float? // celsius
|
|
avgHumidity Decimal? // percentage
|
|
|
|
// Extreme events
|
|
droughtDays Int? @default(0)
|
|
floodDays Int? @default(0)
|
|
stormCount Int? @default(0)
|
|
|
|
// Impact assessment
|
|
cropDamage Decimal? // percentage
|
|
yieldImpact Decimal? // percentage change
|
|
|
|
notes String?
|
|
createdAt DateTime @default(now())
|
|
|
|
// Relations
|
|
season Season @relation(fields: [seasonId], references: [id])
|
|
|
|
@@unique([seasonId, region])
|
|
@@index([seasonId, region])
|
|
@@index([totalRainfall])
|
|
@@index([avgTemperature])
|
|
@@map("season_weather")
|
|
} |