import 'package:json_annotation/json_annotation.dart';
import 'package:drift/drift.dart' hide JsonKey;
import 'package:niogu_app/core/database/app_database.dart';
import 'package:niogu_app/core/enums/sync_status.dart';

part 'outlet_model.g.dart';

@JsonSerializable()
class OutletModel {
  @JsonKey(name: 'id')
  final String serverId;

  final String name;
  
  final String? email;
  
  @JsonKey(name: 'phone_number')
  final String? phoneNumber;
  
  @JsonKey(name: 'full_address')
  final String? fullAddress;
  
  final double? latitude;
  
  final double? longitude;
  
  @JsonKey(name: 'server_photo_url')
  final String? serverPhotoUrl;
  
  @JsonKey(name: 'server_banner_url')
  final String? serverBannerUrl;
  
  @JsonKey(name: 'is_main_outlet')
  final bool? isMainOutlet;
  
  @JsonKey(name: 'is_active')
  final bool? isActive;

  @JsonKey(name: 'created_at')
  final DateTime createdAt;

  @JsonKey(name: 'updated_at')
  final DateTime updatedAt;

  const OutletModel({
    required this.serverId,
    required this.name,
    this.email,
    this.phoneNumber,
    this.fullAddress,
    this.latitude,
    this.longitude,
    this.serverPhotoUrl,
    this.serverBannerUrl,
    this.isMainOutlet,
    this.isActive,
    required this.createdAt,
    required this.updatedAt
  });

  factory OutletModel.fromJson(Map<String, dynamic> json) => _$OutletModelFromJson(json);
  Map<String, dynamic> toJson() => _$OutletModelToJson(this);

  OutletsCompanion toDriftCompanion({String? localPhotoPath, String? localBannerPath}) {
    return OutletsCompanion(
      localId: Value(serverId),
      serverId: Value(serverId),
      name: Value(name),
      email: Value(email),
      phoneNumber: Value(phoneNumber),
      fullAddress: Value(fullAddress),
      latitude: Value(latitude),
      longitude: Value(longitude),
      serverPhotoUrl: Value(serverPhotoUrl),
      serverBannerUrl: Value(serverBannerUrl),
      localPhotoPath: Value(localPhotoPath),
      localBannerPath: Value(localBannerPath),
      isMainOutlet: Value(isMainOutlet ?? false),
      syncStatus: Value(SyncStatus.synced.status),
      createdAt: Value(createdAt),
      updatedAt: Value(updatedAt)
    );
  }
}