func PropertyWritePolicyRule() privacy.MutationRule {
	return privacy.PropertyMutationRuleFunc(func(ctx context.Context, m *ent.PropertyMutation) error {
		propertyID, exists := m.ID()
		if !exists {
			return privacy.Skip
		}
		prop, err := m.Client().Property.Query().
			Where(property.ID(propertyID)).
			WithLocation().
			WithEquipment().
			WithEquipmentPort().
			WithLink().
			WithService().
			WithWorkOrder().
			WithProject().
			Only(ctx)

		if err != nil {
			if !ent.IsNotFound(err) {
				return privacy.Denyf("failed to fetch property: %w", err)
			}
			return privacy.Skip
		}
		p := FromContext(ctx)
		switch {
		case prop.Edges.Location != nil:
			locationTypeID, err := prop.Edges.Location.QueryType().OnlyID(ctx)
			if err != nil {
				if ent.IsNotFound(err) {
					return privacy.Skip
				}
				return privacy.Denyf("failed to fetch location type id: %w", err)
			}
			return allowOrSkipLocations(p.InventoryPolicy.Location.Update, locationTypeID)
		case prop.Edges.Equipment != nil:
			return allowOrSkip(p.InventoryPolicy.Equipment.Update)
		case prop.Edges.EquipmentPort != nil:
			return allowOrSkip(p.InventoryPolicy.Equipment.Update)
		case prop.Edges.Link != nil:
			return allowOrSkip(p.InventoryPolicy.Equipment.Update)
		case prop.Edges.Service != nil:
			return allowOrSkip(p.InventoryPolicy.Equipment.Update)
		case prop.Edges.WorkOrder != nil:
			return allowOrSkipWorkOrder(ctx, p, prop.Edges.WorkOrder)
		case prop.Edges.Project != nil:
			return allowOrSkipProject(ctx, p, prop.Edges.Project)
		}
		return privacy.Skip
	})
}
// PropertyWritePolicyRule grants write permission to property based on policy.
// nolint: dupl
PropertyWritePolicyRule grants write permission to property based on policy.
nolint: dupl
// PropertyWritePolicyRule grants write permission to property based on policy . // nolint : dupl
func PropertyWritePolicyRule() privacy.MutationRule {
	return privacy.PropertyMutationRuleFunc(func(ctx context.Context, m *ent.PropertyMutation) error {
		propertyID, exists := m.ID()
		if !exists {
			return privacy.Skip
		}
		prop, err := m.Client().Property.Query().
			Where(property.ID(propertyID)).
			WithLocation().
			WithEquipment().
			WithEquipmentPort().
			WithLink().
			WithService().
			WithWorkOrder().
			WithProject().
			Only(ctx)
		if err != nil {
			if !ent.IsNotFound(err) {
				return privacy.Denyf("failed to fetch property: %w", err)
			}
			return privacy.Skip
		}
		p := FromContext(ctx)
		switch {
		case prop.Edges.Location != nil:
			locationTypeID, err := prop.Edges.Location.QueryType().OnlyID(ctx)
			if err != nil {
				if ent.IsNotFound(err) {
					return privacy.Skip
				}
				return privacy.Denyf("failed to fetch location type id: %w", err)
			}
			return allowOrSkipLocations(p.InventoryPolicy.Location.Update, locationTypeID)
		case prop.Edges.Equipment != nil:
			return allowOrSkip(p.InventoryPolicy.Equipment.Update)
		case prop.Edges.EquipmentPort != nil:
			return allowOrSkip(p.InventoryPolicy.Equipment.Update)
		case prop.Edges.Link != nil:
			return allowOrSkip(p.InventoryPolicy.Equipment.Update)
		case prop.Edges.Service != nil:
			return allowOrSkip(p.InventoryPolicy.Equipment.Update)
		case prop.Edges.WorkOrder != nil:
			return allowOrSkipWorkOrder(ctx, p, prop.Edges.WorkOrder)
		case prop.Edges.Project != nil:
			return allowOrSkipProject(ctx, p, prop.Edges.Project)
		}
		return privacy.Skip
	})
}
func PropertyWritePolicyRule ( ) privacy . MutationRule { return privacy . PropertyMutationRuleFunc ( func ( ctx context . Context , m * ent . PropertyMutation ) error { propertyID , exists := m . ID ( ) if ! exists { return privacy . Skip } prop , err := m . Client ( ) . Property . Query ( ) . Where ( property . ID ( propertyID ) ) . WithLocation ( ) . WithEquipment ( ) . WithEquipmentPort ( ) . WithLink ( ) . WithService ( ) . WithWorkOrder ( ) . WithProject ( ) . Only ( ctx ) if err != nil { if ! ent . IsNotFound ( err ) { return privacy . Denyf ( " " , err ) } return privacy . Skip } p := FromContext ( ctx ) switch { case prop . Edges . Location != nil : locationTypeID , err := prop . Edges . Location . QueryType ( ) . OnlyID ( ctx ) if err != nil { if ent . IsNotFound ( err ) { return privacy . Skip } return privacy . Denyf ( " " , err ) } return allowOrSkipLocations ( p . InventoryPolicy . Location . Update , locationTypeID ) case prop . Edges . Equipment != nil : return allowOrSkip ( p . InventoryPolicy . Equipment . Update ) case prop . Edges . EquipmentPort != nil : return allowOrSkip ( p . InventoryPolicy . Equipment . Update ) case prop . Edges . Link != nil : return allowOrSkip ( p . InventoryPolicy . Equipment . Update ) case prop . Edges . Service != nil : return allowOrSkip ( p . InventoryPolicy . Equipment . Update ) case prop . Edges . WorkOrder != nil : return allowOrSkipWorkOrder ( ctx , p , prop . Edges . WorkOrder ) case prop . Edges . Project != nil : return allowOrSkipProject ( ctx , p , prop . Edges . Project ) } return privacy . Skip } ) }
PropertyWritePolicyRule grants write permission to property based on policy.
PropertyWritePolicyRule grants write permission to property based on policy .