Skip to main content

Overview

The Beehive entity is the core domain model representing a beehive within an apiary. It extends Equatable for value comparison and contains all essential beehive information including health status, population metrics, and operational details.

Beehive Class

The main entity class that represents a beehive in the domain layer.

Properties

id
String
required
Unique identifier for the beehive
apiaryId
String
required
Reference to the parent apiary where this beehive is located
beehiveNumber
int?
Sequential number identifying the beehive within its apiary
activityLevel
String?
Current activity level of the beehive. Possible values:
  • "Alta" - High activity
  • "Media" - Medium activity
  • "Baja" - Low activity
beePopulation
String?
Population size classification. Possible values:
  • "Alta" - High population
  • "Media" - Medium population
  • "Baja" - Low population
foodFrames
int?
Number of frames dedicated to food storage
broodFrames
int?
Number of frames containing brood (eggs, larvae, and pupae)
hiveStatus
String?
Current operational status of the hive. Possible values:
  • "Cámara de cría y producción" - Brood and production chamber
  • "Cámara de cría y doble alza de producción" - Brood chamber with double production super
  • "Cámara de cría" - Brood chamber only
  • "Cámara de producción" - Production chamber only
healthStatus
String?
Health condition of the beehive. Possible values:
  • "Ninguno" - No health issues
  • "Presencia barroa" - Varroa mite presence
  • "Presencia de plagas" - Pest presence
  • "Enfermedad" - Disease detected
hasProductionChamber
String?
Indicates if the hive has a production chamber. Possible values:
  • "Si" - Yes
  • "No" - No
observations
String?
Free-text field for additional notes and observations about the beehive
createdAt
DateTime?
Timestamp when the beehive record was created
updatedAt
DateTime?
Timestamp when the beehive record was last updated

Methods

fromJson

Factory constructor to create a Beehive instance from JSON data.
factory Beehive.fromJson(Map<String, dynamic> json)
Example:
final json = {
  'id': 'beehive_123',
  'apiary_id': 'apiary_456',
  'hive_number': 5,
  'activity_level': 'Alta',
  'bee_population': 'Media',
  'food_frames': 3,
  'brood_frames': 7,
  'hive_status': 'Cámara de cría y producción',
  'health_status': 'Ninguno',
  'has_production_chamber': 'Si',
  'observations': 'Colony showing good growth',
  'created_at': '2024-01-15T10:30:00Z',
  'updated_at': '2024-01-20T14:45:00Z',
};

final beehive = Beehive.fromJson(json);

toJson

Converts the Beehive instance to a JSON map.
Map<String, dynamic> toJson()
Example:
final beehive = Beehive(
  id: 'beehive_123',
  apiaryId: 'apiary_456',
  beehiveNumber: 5,
  activityLevel: 'Alta',
);

final json = beehive.toJson();
// Returns:
// {
//   'id': 'beehive_123',
//   'apiary_id': 'apiary_456',
//   'hive_number': 5,
//   'activity_level': 'Alta',
//   ...
// }

copyWith

Creates a new Beehive instance with updated values while preserving unchanged properties.
Beehive copyWith({
  String? id,
  String? apiaryId,
  int? beehiveNumber,
  String? activityLevel,
  String? beePopulation,
  int? foodFrames,
  int? broodFrames,
  String? hiveStatus,
  String? healthStatus,
  String? hasProductionChamber,
  String? observations,
  DateTime? createdAt,
  DateTime? updatedAt,
})
Example:
final originalBeehive = Beehive(
  id: 'beehive_123',
  apiaryId: 'apiary_456',
  beehiveNumber: 5,
  activityLevel: 'Media',
);

// Update only the activity level
final updatedBeehive = originalBeehive.copyWith(
  activityLevel: 'Alta',
);

// updatedBeehive now has activityLevel: 'Alta'
// but all other properties remain the same

Enumerations

The beehive domain includes several enumerations for type-safe field values:

Usage Example

import 'package:Softbee/feature/beehive/domain/entities/beehive.dart';

// Create a new beehive instance
final beehive = Beehive(
  id: 'beehive_789',
  apiaryId: 'apiary_123',
  beehiveNumber: 12,
  activityLevel: 'Alta',
  beePopulation: 'Media',
  foodFrames: 4,
  broodFrames: 6,
  hiveStatus: 'Cámara de cría y producción',
  healthStatus: 'Ninguno',
  hasProductionChamber: 'Si',
  observations: 'Strong colony with healthy queen',
  createdAt: DateTime.now(),
);

// Convert to JSON for API transmission
final json = beehive.toJson();

// Create from API response
final receivedBeehive = Beehive.fromJson(apiResponse);

// Update specific fields
final updatedBeehive = beehive.copyWith(
  activityLevel: 'Media',
  foodFrames: 5,
  observations: 'Added additional food frames',
  updatedAt: DateTime.now(),
);

// Value comparison (thanks to Equatable)
final areEqual = beehive == updatedBeehive; // false

Location

Source file: /lib/feature/beehive/domain/entities/beehive.dart

Build docs developers (and LLMs) love